package demo1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-01
 * Time: 10:30
 */
public class TestDemo {

    public static volatile Object locker = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized(locker){
                System.out.println("开始等待");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("结束等待");
            }

        });
        t1.start();
        Thread t2 = new Thread(()->{
            synchronized(locker){
                System.out.println("请输入一个数字开始通知");
                Scanner scan = new Scanner(System.in);
                scan.nextInt();
                locker.notify();
                System.out.println("通知结束");
            }
        });
        t2.start();
    }


}
